<template>
  <div>
    <div id="sourceEcharts" style="width: 100%; height: 230px"></div>
  </div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts'
onMounted(() => {
  handleSourceEcharts()
})
const handleSourceEcharts = () => {
  const myChart = echarts.init(document.getElementById('sourceEcharts'))
  let chartData = [
    { value: 1048, name: 'Search Engine' },
    { value: 735, name: 'Direct' },
    { value: 580, name: 'Email' },
    { value: 484, name: 'Union Ads' },
    { value: 300, name: 'Video Ads' }
  ]
  var option

  option = {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '5%',
      x: 'left',
      left: '60%',
      orient: 'vertical',
      data: chartData.map((item) => {
        return item.name
      })
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['60%', '80%'],
        center: ['25%', '50%'], // 调整中心点位置
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 16,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: chartData
      }
    ]
  }

  option && myChart.setOption(option)
}
</script>

<style scoped></style>
